﻿using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using Nakio.Framework.Server;

namespace Nakio.SystemAdministration.Server
{
    class Program
    {
        static void Main()
        {
            var credentialsAuthentication = new CredentialsAuthentication();
            var server = new ServerContract(credentialsAuthentication);

            var binding = new WSDualHttpBinding(); //new NetTcpBinding();
            var address = new Uri("http://localhost:8000/"); //new Uri("net.tcp://localhost:8000");
            var serviceHost = new ServiceHost(server, address);

            var metadataBehavior = serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
            if (metadataBehavior == null)
            {
                metadataBehavior = new ServiceMetadataBehavior {HttpGetEnabled = true};
                serviceHost.Description.Behaviors.Add(metadataBehavior);
            }

            var serviceDebugBehavior = serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
            if (serviceDebugBehavior == null)
            {
                serviceDebugBehavior = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true,
			                                                      HttpHelpPageEnabled = true };
                serviceHost.Description.Behaviors.Add(serviceDebugBehavior);
            }
            else
            {
                serviceDebugBehavior.IncludeExceptionDetailInFaults = true;
                serviceDebugBehavior.HttpHelpPageEnabled = true;
            }

            serviceHost.AddServiceEndpoint(typeof (IServerContract), binding, "SystemAdministration");
            serviceHost.Open();
            
            Console.ReadKey();
        }
    }
}